﻿$(function () {
    
    $.util.namespace("ua");

    ua.initForm = function (selector) {
        $(selector ? selector : "body").find("form").each(function () {
            var form = $(this),
                array = form.find("input,textarea,select,:button").not(":hidden");
            array.keydown(function (e) {
                if (e.which == 13 && !$(this).is(":button")) {
                    var i = array.index(this),
                        index = (i > -1 && i < array.length - 1) ? (i + 1) : 0;
                    array.eq(index).focus();
                }
            }).eq(0).focus();

            form.submit(function () {
                return $(this).form("validate");
            });

            form.find(":button.submit").click(function () {
                form.submit();
            });
            form.find(":button.reset").click(function () {
                form.form("reset");
            });
            form.find(":button.cancel").click(function () {
                var returnUrl = $.util.request["returnUrl"];
                if (returnUrl) {
                    window.location.href = returnUrl;
                } else {
                    window.history.go(-1);
                }
            });
        });
    };

    ua.initForm();

    



});